//
//  BusinessCircleRequestManager.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 16/8/23.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "BusinessCircleRequestManager.h"

#if __has_include(<Commom/SEGFindDictionaryInfoManagr.h>)
#import <Commom/SEGFindDictionaryInfoManagr.h>
#else
#import "SEGFindDictionaryInfoManagr.h"
#endif

@implementation BusinessCircleRequestManager
/**
 *  请求分类信息 可替换[[ServiceInterface sharedServiceInterface] findDictionaryInfo:
 *
 *  @param finished 网络请求完成后的操作
 */
+ (void)requesFindDictionaryInfoWithCode:(NSString *)code finished:(SEGNetworkRequestCallBack)finished {
    
    // 3. 网路请求方法(必须添加)
    [[SEGFindDictionaryInfoManagr sharedManager] requestDictionaryInfoByCode:code completed:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull codeType, NSString * _Nonnull errorMessage) {
        if (!isSuccessed) {
            finished(result,nil);
            return ;
        }
        
        NSDictionary *responseDic = result;
        NSString *code = [responseDic objectForKey:@"code"];
        NSString *message = [responseDic objectForKey:@"message"];
        NSDictionary *data = [responseDic objectForKey:@"data"];
        
        NSMutableDictionary* notifyDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:message,@"message",code,@"code",nil];
        
        if([code isEqualToString:@"0"])
        {
            NSArray *result=[data objectForKey:@"result"];
            NSMutableArray *nameList = [NSMutableArray arrayWithCapacity:result.count];
            NSMutableArray *valueList = [NSMutableArray arrayWithCapacity:result.count];
            
            for (NSDictionary* aDic in result) {
                [nameList addObject:[aDic valueForKey:@"name"]];
                [valueList addObject:[aDic valueForKey:@"value"]];
                
            }
            
            [notifyDic setObjectExtra:nameList  forKey:@"nameList"];
            [notifyDic setObjectExtra:valueList  forKey:@"valueList"];
            
        }
        finished(notifyDic,nil);
    }];
}

/**
 请求优惠列表

 @param param param
 @param finished finished
 */
+ (void)requestPrivilegeListWithParam:(NSDictionary *)param finished:(SEGNetworkReponse)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/rest-api/v1/community-merchant/item-list.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:param finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
}

/**
 *   请求优惠详情 可替换loadNetData ApiName为kPrivilegeDetail的方法
 *
 *  @param requestId
 *  @param finished 网络请求完成后的操作
 */
+ (void)requestPrivilegeDetaillWithItemSid:(NSString*)itemSid finished:(SEGNetworkReponse)finished {
    
    // 3. 网路请求方法(必须添加)
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:itemSid, @"itemSid", nil];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/rest-api/v1/community-merchant/item-detail.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];

}

/**
 请求商户列表

 @param param param
 @param finished finish
 */
+ (void)requestMerchantListWithParam:(NSDictionary *)param finished:(SEGNetworkReponse)finished {
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/rest-api/v1/community-merchant/merchant-list.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:param finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
}

/**
 *   请求商户详情 可替换loadNetData ApiName为kMerchantDetail的方法
 *
 *  @param requestId
 *  @param finished 网络请求完成后的操作
 */
+ (void)requestMerchantDetailWithMerchantSid:(NSString*)merchantSid finished:(SEGNetworkReponse)finished {
    
    // 3. 网路请求方法(必须添加)
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:merchantSid, @"merchantSid", nil];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/rest-api/v1/community-merchant/merchant-detail.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(isSuccessed, result, codeType, errorMessage);
    }];
}

/**
 *   请求商户详情 可替换[[BusinessManager sharedManager].privilegeEntityManager requestBuyProductWithPrivilegeID
 *
 *  @param requestId
 *  @param finished 网络请求完成后的操作
 */
+ (void)requestBuyProductWithPrivilegeID:(NSString*)privilegeID merchantSid:(NSString *)merchantSid orderType:(NSString *)orderType finished:(SEGNetworkRequestCallBack)finished {
    
    // 3. 网路请求方法(必须添加)
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:privilegeID,@"itemSid",merchantSid,@"merchantSid",orderType,@"orderType",nil];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/rest-api/v1/community-merchant/submit-order.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(result,nil);
    }];
}

@end
